$(function () {
    obj.init();
});

var obj = new function() {
    return {
        dataGrid: null,
        dom: {
            search: null,
            startDom: null,
            endDom: null
        },
        init: function () {
            this.dom.startDom = $('#list_search_startTime').datebox();
            this.dom.endDom = $('#list_search_endTime').datebox();
            this.dom.startDom.datebox('setValue', this.GetDateStr(-30));
            this.dom.endDom.datebox('setValue', this.GetDateStr(0));
            this.dataGrid = new xhDataGrid($('#list'), 'res/getReferApplyStat',{search: {startTime: this.dom.startDom.getElementValue(), endTime: this.dom.endDom.getElementValue()}});
            this.dataGrid.parseToolbar().init();
            this.dom.search = $('#bt_list_search');
            xhExtra.clearLoadSuccess(this.dataGrid);
            this.listener();
        },
        listener: function () {
            var $this = this;
            //查询
            $this.dom.search.click(function () {
                $this.funObj().search();
            });
            xhTool.bindDocKeyDown($this.dom.search);
            //获取区域数据
            $('#school_area').combotree({
                url: 'getDepData',
                animate:true,
                onLoadSuccess:function(node,data){
                    $length = data.length;
                    $.each(data,function (id,value) {
                        if (value.children !== undefined) {
                            $length = $length + value.children.length;
                        }
                    })
                },
                onShowPanel:function(){
                    if ($length <= 8){
                        $(this).combobox('panel').height("auto");//高度自适应
                    }else{
                        $(this).combobox('panel').height("200");//高度自定义
                    }
                },
                onBeforeSelect: function (node) {
                    var t = $(this).tree;
                    var isLeaf = t('isLeaf', node.target);
                    if (!isLeaf) {//选择的不是叶子节点
                        return false;
                    }
                }
            });
            //双击
            this.dataGrid.onDblClickRow = function(rowIndex, rowData){
                var iSchoolId = rowData['iSchoolId'];
                var schoolName = rowData['sSchoolName'];
                $this.funObj().showDetail(iSchoolId, schoolName);
            };
        },
        funObj: function () {
            var $this = this;
            return {
                search: function () {
                    $this.dataGrid.reload({
                        search: {
                            vague: xhExtra.getValue($('#list_vague')),
                            startTime: $this.dom.startDom.getElementValue(),
                            endTime: $this.dom.endDom.getElementValue(),
                            school_area: $('#school_area').combotree('getValue')
                        }
                    })
                },
                showDetail: function (iSchoolId, schoolName) {
                    window.top.xhTop.showModal({
                        title: schoolName + '：教师申请情况',
                        content: xhTool.getFrameString('res/getTeaNumDetail', {schoolId: iSchoolId}, 500),
                        size: 'md',
                        button: true,
                        backClose: false
                    });
                }
            }
        },
        GetDateStr: function(AddDayCount) {
            var dd = new Date();
            dd.setDate(dd.getDate()+AddDayCount);//获取AddDayCount天后的日期
            var y = dd.getFullYear();
            var m = dd.getMonth()+1;//获取当前月份的日期
            var d = dd.getDate();
            fina = y+"-"+m+"-"+d;
            return fina;
        }
    }
};

